﻿/** 装甲勇士,在一般UI的基础上新增了RCtrl键转换秘籍种类的功能

  By setycyas @2023-10-14
*/

/* 全局设定
*/
#Warn
#MaxThreadsPerHotkey 1
SetWorkingDir(A_ScriptDir)
#Include "..\Class\FaceDetector.2.ahk"
#Include "..\Class\CommonMacro.2.ahk"
#Include "..\Class\CommonUI.2.ahk"
#Include "..\Class\MyFuns.2.ahk"
#Include "..\Class\MyEmu.2.ahk"
#Include "..\Class\OrderMap.2.ahk"
SendMode("Input")

/* 制作装甲勇士的宏类
*/
class ArmwarMacro extends CommonMacro {

  pressDuration := 40
  ;作弊武器种类和当前作弊种类ID,因为牵涉到按键设定所以在首次提交数据
  ;时再制作cheatTypes
  cheatTypes := OrderMap()
  cheatID := 1

  /* 技能函数 
  */
  skill(skillKey, direction){
    this._down(1)
    sleep(100)
    MyFuns.keyDown(direction)
    sleep(100)
    MyFuns.keyUp(direction)
    ;等待key松开再发送A键松开
    while (MyFuns.getKeyState(skillKey)) {
      sleep(50)
    }
    this._up(1)
  }
  
  /* 宏函数
  */
  _A上(key){
    this.skill(key, "up")
  }
  _A下(key){
    this.skill(key, "down")
  }
  _A左(key){
    this.skill(key, "left")
  }
  _A右(key){
    this.skill(key, "right")
  }
  
  ;秘籍,每关开头按住方向键+BC选择武器
  _武器秘籍(key){
    local cheatWeapon := this.cheatTypes.getKeys()[this.cheatID]
    local keys := this.cheatTypes[cheatWeapon]
    local i, k
    for i, k in keys {
      MyFuns.keyDown(k)
      sleep(50)
    }
    ;等待key松开再松开所有键
    while (MyFuns.getKeyState(key)) {
      sleep(50)
    }
    for i, k in keys {
      MyFuns.keyUp(k)
      sleep(50)
    }
  }
  
  ;涡轮浮空
  /*
  _涡轮浮空(key){
   this._down(2)
   sleep(3500)
   this._up(2)
  }
  */
  _涡轮浮空(key){
    this._down(2)
    sleep(100)
    if (MyFuns.getKeyState(key)){
      this._连发A(key)
    }
    this._up(2)
  }

  /* 重载宏接口
  */
  _setMacro(){
    this.macroMap := OrderMap()
    this.macroMap["连发A"] := this._连发A.bind(this)
    this.macroMap["A上"] := this._A上.bind(this)
    this.macroMap["A下"] := this._A下.bind(this)
    this.macroMap["A左"] := this._A左.bind(this)
    this.macroMap["A右"] := this._A右.bind(this)
    this.macroMap["涡轮浮空"] := this._涡轮浮空.bind(this)
    this.macroMap["武器秘籍"] := this._武器秘籍.bind(this)
    this.macroArr := this.macroMap.getKeys()
  }

}

/* 制作装甲勇士专用UI
*/
class ArmwarUI extends CommonUI {

  DEFAULT_HOTKEYS := "~d,~s,e,~r,~g,~v"
  EXE_ARRAY := [MyEmu.WINKAWAKS, MyEmu.FBAS, MyEmu.XZONE]

  /* 构造函数
  */
  __New(macro){
    super.__New("装甲勇士", macro)
    this._preset := Map(
      "默认", ["连发A", "A左", "A上", "涡轮浮空", "A右", "武器秘籍"])
  }

  /* 重写接口
  */
  ;首次提交数据时绑定RCtrl键为秘籍武器转换热键并制作秘籍表
  _onSubmitEnd(){
    super._onSubmitEnd()
    local ct := this._macro.cheatTypes
    local keyB := this._macro._keys[2]
    local keyC := this._macro._keys[3]
    if (this._submitTimes == 0){
      HotIfWinActive(this._winTitle)
      Hotkey("RCtrl", this._changeCheatWeapon.bind(this))
      HotIfWinActive()
      ct["D_DRILL"] := ["up", keyB, keyC]
      ct["F_CLAW"] := ["right", keyB, keyC]
      ct["C_SPARK"] := ["down", keyB, keyC]
      ct["L_BLADE"] := ["left", keyB, keyC]
      ct["FLAME"] := ["left", "down", keyB, keyC]
      ct["LASER"] := ["right", "down", keyB, keyC]
      ct["BOMB"] := ["left", "up", keyB, keyC]
      ct["MISSILE"] := ["right", "up", keyB, keyC]
    }
  }

  /* 重写setup,更改可选的exe,读入预设
  */
  setup(){
    super.setup()
    this._myGui.opt("+AlwaysOnTop")
    this._myGui.show("x1100 y330")
    this.readPresetMenu("默认")
  }

  /* 预设秘籍武器转换
  */
  _changeCheatWeapon(key){
    local cheatWeapon := ""
    this._macro.cheatID += 1
    if (this._macro.cheatID > 8) {
      this._macro.cheatID := 1
    }
    cheatWeapon := this._macro.cheatTypes.getKeys()[this._macro.cheatID]
    this._statusBar.SetText(cheatWeapon)
  }

}

/* 运行当前脚本
*/
if (A_ScriptName == "装甲勇士.2.ahk"){
  face := FaceDetector() ;方向检测对象
  macro := ArmwarMacro(face, ["q", "f", "c"]) ;宏对象,有界面时第二个参数可以随便写但长度不要小于2
  ;新建界面并设定
  ui := ArmwarUI(macro)
  ui.setup()
  ui._exeComboBox.Choose(MyEmu.WINKAWAKS)
  ui._gameKeyEdit.Text := "q,f,c"
  ;ui._hotkeyEdit.Text := "~d,s,c,e,r,g"
  ui._fpsEdit.Text := 10
  ui.readPresetMenu("默认")
}